import model.Position;
import model.Stage;
import agentInterface.AGVDetails;
import agentInterface.MachineDetails;
import agentInterface.PowerDetails;
import agents.AgvAgent;
import agents.FactoryAgent;
import agents.MachineAgent;
import agents.PowerAgent;
import jade.core.Runtime; 
import jade.core.Profile; 
import jade.core.ProfileImpl; 
import jade.wrapper.*; 

public class Run {
	public static void main( String arg[] ) {
		// Get a hold on JADE runtime 
		Runtime rt = Runtime.instance(); 
		// Create a default profile    
		Profile p = new ProfileImpl();     
		// Create a new non-main container, connecting to the default 
		// main container (i.e. on this host, port 1099) 
		ContainerController cc = rt.createMainContainer(p); 
		
		MachineAgent mac1 = new MachineAgent(Stage.init,new Position(10f,85f));
		MachineAgent mac2 = new MachineAgent(Stage.paint,new Position(45f,95f));
		MachineAgent mac3 = new MachineAgent(Stage.lather,new Position(90f,85f));
		MachineAgent mac4 = new MachineAgent(Stage.rinse,new Position(10f,60f));
		MachineAgent mac5 = new MachineAgent(Stage.wrap,new Position(40f,70f));
		MachineAgent mac6 = new MachineAgent(Stage.init,new Position(70f,50f));
		MachineAgent mac7 = new MachineAgent(Stage.paint,new Position(40f,30f));
		MachineAgent mac8 = new MachineAgent(Stage.lather,new Position(80f,30f));
		MachineAgent mac9 = new MachineAgent(Stage.rinse,new Position(20f,10f));
		MachineAgent mac10 = new MachineAgent(Stage.wrap,new Position(60f,10f));
		
		AgvAgent agv1 = new AgvAgent(new Position(45f,45f));
		AgvAgent agv2 = new AgvAgent(new Position(50f,50f));
		AgvAgent agv3 = new AgvAgent(new Position(40f,50f));
		
		PowerAgent pwr1 = new PowerAgent(new Position(10f,75f));
		PowerAgent pwr2 = new PowerAgent(new Position(95f,20f));
		
		FactoryAgent fac1 = new FactoryAgent();
		
		try {
			//AgentController dummy = cc.createNewAgent("sfdds", "agents.AgvAgent", null);
			AgentController rma = cc.createNewAgent("rma", "jade.tools.rma.rma", null);
			
			AgentController f1 = cc.acceptNewAgent("fac1", fac1);
			
			AgentController m1 = cc.acceptNewAgent("mac1", mac1);
			AgentController m2 = cc.acceptNewAgent("mac2", mac2);
			AgentController m3 = cc.acceptNewAgent("mac3", mac3);
			AgentController m4 = cc.acceptNewAgent("mac4", mac4);
			AgentController m5 = cc.acceptNewAgent("mac5", mac5);
			AgentController m6 = cc.acceptNewAgent("mac6", mac6);
			AgentController m7 = cc.acceptNewAgent("mac7", mac7);
			AgentController m8 = cc.acceptNewAgent("mac8", mac8);
			AgentController m9 = cc.acceptNewAgent("mac9", mac9);
			AgentController m10 = cc.acceptNewAgent("mac10", mac10);
			
			AgentController a1 = cc.acceptNewAgent("agv1", agv1);
			AgentController a2 = cc.acceptNewAgent("agv2", agv2);
			AgentController a3 = cc.acceptNewAgent("agv3", agv3);
			
			fac1.setAgvDetails(agv1.getLocalName(), new AGVDetails(agv1));
			fac1.setAgvDetails(agv2.getLocalName(), new AGVDetails(agv2));
			fac1.setAgvDetails(agv3.getLocalName(), new AGVDetails(agv3));
			
			AgentController p1 = cc.acceptNewAgent("pwr1", pwr1);
			AgentController p2 = cc.acceptNewAgent("pwr2", pwr2);
			
			fac1.setPowerDetails(pwr1.getLocalName(), new PowerDetails(pwr1));
			fac1.setPowerDetails(pwr2.getLocalName(), new PowerDetails(pwr2));
			
			fac1.setMachineDetails(mac1.getLocalName(), new MachineDetails(mac1));
			fac1.setMachineDetails(mac2.getLocalName(),  new MachineDetails(mac2));
			fac1.setMachineDetails(mac3.getLocalName(),  new MachineDetails(mac3));
			fac1.setMachineDetails(mac4.getLocalName(), new MachineDetails(mac4));
			fac1.setMachineDetails(mac5.getLocalName(),  new MachineDetails(mac5));
			fac1.setMachineDetails(mac6.getLocalName(),  new MachineDetails(mac6));
			fac1.setMachineDetails(mac7.getLocalName(),  new MachineDetails(mac7));
			fac1.setMachineDetails(mac8.getLocalName(), new MachineDetails(mac8));
			fac1.setMachineDetails(mac9.getLocalName(),  new MachineDetails(mac9));
			fac1.setMachineDetails(mac10.getLocalName(),  new MachineDetails(mac10));
			
			//start agents, pops up ui
			rma.start();
			f1.start();			
			m1.start(); 
			m2.start();
			m3.start();
			m4.start(); 
			m5.start();
			m6.start();
			m7.start(); 
			m8.start();
			m9.start();
			m10.start();
			
			a1.start();
			a2.start();
			a3.start();
			
			p1.start();
			p2.start();
			
		} catch (StaleProxyException e) {
			e.printStackTrace();
		} 
		// Fire up the a
		
	}
}
